var express = require("express");
var router = express.Router();
var pomelo = require("pomelo");

//通过key查询配置
router.get("/getConfigByKey", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.configRemote.getConfigByKey(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

//查询所有配置
router.get("/getAllConfigs", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.configRemote.getAllConfigs(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

//根据key修改value
router.get("/updateConfigValue", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.configRemote.updateConfigValue(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

//根据key修改enable
router.get("/updateConfigEnable", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.configRemote.updateConfigEnable(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

//插入配置
router.get("/addConfig", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.configRemote.addConfig(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

//通过key删除配置
router.get("/deleteConfigByKey", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.configRemote.deleteConfigByKey(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

module.exports = router;